package com.android.functionmanagement.adapter;

import java.util.ArrayList;
import android.content.Context;
import android.widget.BaseAdapter;

/**
 * 
 * 类名: BaseApdater <br/>
 * 功能描述: 基础adapter适配器 <br/>
 * 日期: 2013-9-23 上午10:36:06 <br/>
 * 
 * @author fmh
 * @version @param <T>
 */
public abstract class BaseApdater<T> extends BaseAdapter {
	/**
	 * 数据
	 */
	protected ArrayList<T> mList = new ArrayList<T>();
	
	protected Context mContext;

	public BaseApdater(ArrayList<T> mList, Context mcContext) {
		super();
		this.mList = mList;
		this.mContext = mcContext;
	}
	/**
	 * 获取当前所有数据
	 * @return
	 */
	public ArrayList<T> getList() {
		return mList;
	}

	/**
	 * appendToList:添加多条 <br/>
	 * 
	 */
	public void appendToList(ArrayList<T> list) {
		if (list == null) {
			return;
		}
		mList.addAll(list);
		notifyDataSetChanged();
	}
	
	/**
	 * appendToList:添加单条到list的顶部 <br/>
	 * 
	 */
	public void appendOneToListTop(T t) {
		if (t == null) {
			return;
		}
		mList.add(0, t);
		notifyDataSetChanged();
	}

	/**
	 * appendToTopList:添加多条在最前面 <br/>
	 * 
	 */
	public void appendToTopList(ArrayList<T> list) {
		if (list == null) {
			return;
		}
		mList.addAll(0, list);
		notifyDataSetChanged();
	}

	/**
	 * clearAll:清除全部显示 <br/>
	 * 
	 */
	public void clearAll() {
		mList.clear();
		notifyDataSetChanged();
	}

	/**
	 * clearByOne:清除单条显示 <br/>
	 * 
	 */
	public void clearByOne(Object object) {
		mList.remove(object);
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		return mList.size();
	}

	@Override
	public Object getItem(int position) {
		if (position > mList.size() - 1) {
			return null;
		}
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
	
}
